<!DOCTYPE HTML>
<html>
<head>
  <title>问卷调查管理</title>
  <link rel="stylesheet" href="/stylesheets/style.css">
  <script src="/scripts/jquery.min.js"></script>
  <script src="/scripts/boot.js" type="text/javascript"></script>
  <link rel="stylesheet" href="/scripts/miniui/themes/default/miniui.css">
  <link rel="stylesheet" href="/scripts/miniui/themes/icons.css">
  <link rel="stylesheet" href="/scripts/miniui/themes/bootstrap/skin.css">
  <link rel="stylesheet" href="/editor/common.css">
  <script src="/scripts/miniui/miniui.js"></script>
</head>
<body style="padding: 0;width: 100%;height: 98%">
<div style="width:100%;height:88%;">

  <!--<div id="outImg">-->
    <!--<img id="imgId" src="" alt="" onclick="smallImg()">-->
  <!--</div>-->
  <div style="padding: 5px">
    <span>问卷类型：</span><input class="mini-combobox" type="text" id="type" name="type" value="-1" data="questionType"/>
    <span>问卷标题：</span><input class="mini-textbox" type="text" id="title"/>
    <span>问卷网址：</span><input class="mini-textbox" type="text" id="url"/>
    <a class="mini-button" iconCls="icon-search" onclick="search()">查找</a>
  </div>
  <div style="width:99%;">
    <div class="mini-toolbar" style="border-bottom:0;padding:0px;">
      <table style="width:100%;">
        <tr>
          <td style="width:100%;">
            <a class="mini-button" iconCls="icon-add" onclick="add()">添加</a>
            <a class="mini-button" iconCls="icon-edit" onclick="edit()">编辑</a>
            <a class="mini-button" iconCls="icon-remove" onclick="del()">删除</a>
          </td>
        </tr>
      </table>
    </div>
  </div>
  <div id="datagrid1" class="mini-datagrid" style="width:99%;height: 100%;"
       url="/getdata/questionManger" idField="id" allowResize="true"
       sizeList="[20,30,50,100]" pageSize="20">
    <div property="columns">
      <div type="checkcolumn" width="20"></div>
      <div field="objectId" width="80" align="center" headerAlign="center">问卷ID</div>
      <div field="type" width="80" align="center" headerAlign="center">问卷类型</div>
      <div field="title" width="80" align="center" headerAlign="center">问卷标题</div>
      <div field="url" width="100" align="center" headerAlign="center">问卷网址</div>
      <div field="createdAt" width="80" align="center" headerAlign="center">创建时间</div>
    </div>
  </div>
</div>
</body>
<script type="text/javascript">
  var questionType = [{ id: -1, text: ' ' },{ id: 0, text: 'LIVE' }, { id: 1, text: 'TASK'}];
  var flag = 1;
  mini.parse();
  var grid = mini.get("datagrid1");
  grid.load();
  function edit() {
    var row = grid.getSelected();
    if (row) {
//      console.log(row)
      mini.open({
        url: "/getdata/questionEdit?objectId="+row.objectId,
        title: "编辑问卷调查", width: 300, height: 220,
        ondestroy: function (action) {
          grid.reload();
        }
      });
    } else {
      alert("请选中一个部落!");
      return;
    }
  }
  function add() {
    mini.open({
      url: "/editor/questionAdd",
      title: "添加问卷调查", width: 300, height: 200,
      ondestroy: function (action) {
        grid.reload();
      }
    });
  }
  function del() {
    var row = grid.getSelected();
    if (row) {
      var objectId = row.objectId;
//      console.log(objectId)
      $.ajax({
        url: "/getdata/questionRemove",
        type: 'post',
        data: {objectId: objectId},
        cache: false,
        success: function (result) {
          if (result == '1'){
            alert('问卷调查删除成功！');
          } else {
            alert('问卷调查删除失败！');
          }
          grid.reload();
        },
        error: function (error) {
          console.log(error)
        }
      });
    } else {
      alert("请选中一条记录");
    }
  };
  function search() {
    var title = mini.get("title").getValue();
    var url = mini.get("url").getValue();
    var type = mini.get("type").getValue();
    if (type == 0){
      type = 'LIVE'
    } else if (type == 1){
      type = 'TASK'
    } else {
      type = ''
    }
    grid.load({
      type: type,
      title: title,
      url: url,
    });
  }
</script>
</html>